package com.museum;

import java.io.IOException;
import java.io.StringReader;
import java.net.URI;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.Vector;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xmlrpc.android.XMLRPCClient;
import org.xmlrpc.android.XMLRPCException;

import com.museum.data.Mp_Places_Items_Handler;
import com.museum.data.Mp_Places_Museum_Handler;
import com.museum.data.Mp_Places_News_Handler;
import com.museum.data.Mp_User_Bookshelf_Handler;
import com.museum.data.Mp_User_Profile_Handler;
import com.museum.data.Mp_User_Visit_Handler;
import com.museum.data.Mp_User_Watched_Handler;
import com.museum.model.Location;
import com.museum.model.Mp_Places_Items;
import com.museum.model.Mp_Places_Museum;
import com.museum.model.Mp_User_Watched;
import com.museum.model.Open_Date;
import com.museum.model.Open_Date_Item;
import com.museum.model.Place;
import com.museum.model.Visited;
import com.museum.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.support.v4.app.NavUtils;
import android.view.View.OnClickListener;

public class Mp_Places_Items_Activity extends Activity {
	TextView textviewDetail;
	
	private XMLRPCClient client;
	private URI uri;
	Visited visited;
	Place place;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mp_places_items);
        
        bindWidget();
        setButtonEventListener();
        
        String place_id = "57";
        String result = "";
      //##############Mp_Places_Items##################
        Mp_Places_Items_Handler f = new Mp_Places_Items_Handler(place_id);
        for(int i = 0; i < f.getMp_Places_Items().getItemCount(); i++){
     	   
     	  //String place_Email = f.getMp_Places_Items().getItem(i).getExhibition_place().getEmail();
     	  String item_id = f.getMp_Places_Items().getItem(i).getItem_Id();
     	  String displayName = f.getMp_Places_Items().getItem(i).getDisplay_name();
     	  String description = f.getMp_Places_Items().getItem(i).getDescription();
     	  String keywords = f.getMp_Places_Items().getItem(i).getKeywords();
     	  String dated_added = f.getMp_Places_Items().getItem(i).getDated_added();
     	  String related_to = f.getMp_Places_Items().getItem(i).getRelated_to();
     	  
     	  result += "\r\nitem_id: " + item_id
     			  	+"\r\n"+ "displayName: "+ displayName
     			  	+"\r\n"+ "description: "+ description
     			  	+"\r\n"+ "keywords: "+ keywords
     			  	+"\r\n"+ "dated_added: "+ dated_added
     			  	+"\r\n"+ "related_to: "+ related_to;
     	  
	     	String Exhi_place_id = f.getMp_Places_Items().getItem(i).getExhibition_place().getPlaceId();
	       	String name = f.getMp_Places_Items().getItem(i).getExhibition_place().getName();
	   	    String Exhi_description = f.getMp_Places_Items().getItem(i).getExhibition_place().getDescription();
	   	    String create_timestamp = f.getMp_Places_Items().getItem(i).getExhibition_place().getCreate_Timestamp();
	   	    String add_timestamp = f.getMp_Places_Items().getItem(i).getExhibition_place().getAdded_Timestamp();
	   	    String location_description =f.getMp_Places_Items().getItem(i).getExhibition_place().getLocation().getDescription();
	   	    String location_latitude = f.getMp_Places_Items().getItem(i).getExhibition_place().getLocation().getLatitude();
	   	    String location_longitude = f.getMp_Places_Items().getItem(i).getExhibition_place().getLocation().getLongitude();
	   	    String website = f.getMp_Places_Items().getItem(i).getExhibition_place().getWebsite();
	   	    String email = f.getMp_Places_Items().getItem(i).getExhibition_place().getEmail();
		    result += "\r\nExhi_place_id: " + Exhi_place_id
		     			 +"\r\n"+ "name: "+ name
		     			 +"\r\n"+ "Exhi_description: "+ Exhi_description
		     			 +"\r\n"+ "create_timestamp: "+ create_timestamp
		     			 +"\r\n"+ "add_timestamp: "+ add_timestamp
		     			 +"\r\n"+ " location_description: "+ location_description
		     			 +"\r\n"+ " location_latitude: "+ location_latitude
		     			 +"\r\n"+ " location_longitude: "+ location_longitude
		     			 +"\r\n"+ "website: "+ website
		     			 +"\r\n"+ "email: "+ email;
	  			 
	   	    for(int j=0;j < f.getMp_Places_Items().getItem(i).getExhibition_place().getOpen_Date().getItemCount();j++){
	   	    	String open_date = f.getMp_Places_Items().getItem(i).getExhibition_place().getOpen_Date().getItem(j).getDate();
	   	    	String open_time = f.getMp_Places_Items().getItem(i).getExhibition_place().getOpen_Date().getItem(j).getOpen_time();
	   	    	String close_time = f.getMp_Places_Items().getItem(i).getExhibition_place().getOpen_Date().getItem(j).getClose_time();
	   	    	
	   	    	result += "\r\n"+ " open_date: "+ open_date
				   			 +"\r\n"+ " open_time: "+ open_time
				   			 +"\r\n"+ " close_time: "+ close_time;
	   	    }
	   	    String status = f.getMp_Places_Items().getItem(i).getExhibition_place().getStatus();
	   	    String exhibition_status = f.getMp_Places_Items().getItem(i).getExhibition_place().getExhibition_Status();
   	    
	   	  result += "\r\n"+ "status: "+ status
			   			 +"\r\n"+ "exhibition_status: "+ exhibition_status;
        }
        textviewDetail.setText(result);
    }
    private void bindWidget(){
    	textviewDetail = (TextView)findViewById(R.id.textviewDetail);
    }
    private void setButtonEventListener(){

    }

}
